package com.hqq.dao;

import com.hqq.domain.WoocUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * WoocUserDao
 * Created by heqianqian on 2018/3/25.
 */
@Repository
public interface WoocUserDao {

    String TABLE_NAME = "wooc_user";
    String SELECT_FIELD = "user_id as userId,user_name as userName,user_pwd as userPwd," +
            "user_gender as userGender,user_type as userType,user_score as userScore,user_profile as userProfile";
    String INSERT_FIELD = "user_name,user_pwd,user_gender,user_type,user_score,user_profile";

    /**
     * 查询单个用户
     *
     * @param woocUser
     * @return
     */
    WoocUser findWoocUser(WoocUser woocUser);


    /**
     * 根据id查询
     *
     * @param userId
     * @return
     */
    @Select("SELECT " + SELECT_FIELD + " FROM " + TABLE_NAME + " WHERE user_id = #{userId}")
    WoocUser findWoocUserById(@Param("userId") Long userId);

    /**
     * 保存用户信息
     *
     * @param woocUser
     */
    @SelectKey(before = false, statement = "SELECT LAST_INSERT_ID() AS userId", keyProperty = "userId", resultType = Long.class)
    @Insert("INSERT INTO " + TABLE_NAME + "(" + INSERT_FIELD + ") VALUES(#{userName},#{userPwd},#{userGender},#{userType},#{userScore},#{userProfile})")
    void insertUser(WoocUser woocUser);
}
